//
//  Tests.cpp
//  party-family
//
//  Uses the Google C++ Testing Framework
//  For more, see: http://code.google.com/p/googletest/
//
//  Created by Justin Kurtz on 7/7/11.
//

#include "gtest/gtest.h"
#include "../game/Health.h"
#include "../game/Item.h"
#include "../game/Player.h"

TEST(Health, DefaultConstructor) {
   
   Health *health = new Health();

   // default health should be 100
   EXPECT_EQ(health->GetHealth(), 100);
}

TEST(Health, CustomMaxHealth) {
   
   Health *health = new Health(93);
   
   // custom max health
   EXPECT_EQ(health->GetHealth(), 93);
}

TEST(Health, Damage) {
   
   Health *health = new Health();
   
   // health is at 100
   health->Damage(51);
   
   EXPECT_EQ(health->GetHealth(), 49);
   
   health->Damage(1);
   
   EXPECT_EQ(health->GetHealth(), 48);
   
   health->Damage(0);
   
   EXPECT_EQ(health->GetHealth(), 48);
   
   health->Damage(-2);
   
   EXPECT_EQ(health->GetHealth(), 50);
}

TEST(Health, KillAndRebirth) {
   
   Health *health = new Health();
   
   // health is at 100
   health->Damage(5000);
   // health shouldn't ever go below 0
   EXPECT_EQ(health->GetHealth(), 0);
   // and we shouldn't be alive
   EXPECT_EQ(health->IsAlive(), false);
   
   health->Damage(-1);
   // damaging negative health
   EXPECT_EQ(health->GetHealth(), 1);
   // and we should be alive
   EXPECT_EQ(health->IsAlive(), true);
   
   health->Damage(-1000);
   // damaging negative health, and shouldn't go above max
   EXPECT_EQ(health->GetHealth(), 100);
   // and we should be alive
   EXPECT_EQ(health->IsAlive(), true);
   
}

TEST(Health, Heal) {
   
   Health *health = new Health(93);
   
   // custom max health
   EXPECT_EQ(health->GetHealth(), 93);
   
   health->AddHealth(7);
   // health shouldn't ever go past the maximum, which is 93.
   EXPECT_EQ(health->GetHealth(), 93);
}

TEST(Health, HealKill) {
   
   Health *health = new Health(93);
   
   // custom max health
   EXPECT_EQ(health->GetHealth(), 93);
   
   health->AddHealth(-3);
   // adding negative health.
   EXPECT_EQ(health->GetHealth(), 90);
   
   health->AddHealth(-1000);
   // adding negative health.
   EXPECT_EQ(health->GetHealth(), 0);
   // dead
   EXPECT_EQ(health->IsAlive(), false);
}

// ITEM TESTS
TEST(Item, Description) {
   Item *item = new Item(1337);
   
   item->SetDescription("Hallo");
   EXPECT_EQ(item->GetDescription(), "Hallo");
   
   item->SetDescription("Tot Ziens");
   EXPECT_EQ(item->GetDescription(), "Tot Ziens");

}

// PLAYER TESTS

TEST(Player, DefaultConstructor) {
   Player *player = new Player();
   
   // player should have full health (100)
   EXPECT_EQ(player->GetHealth(), 100);
   EXPECT_EQ(player->GetHealthPercentage(), 1);
   EXPECT_EQ(player->IsAlive(), true);
   
   // player should have an empty inventory
   EXPECT_EQ(player->GetNumItems(), 0);
}

TEST(Player, Kill) {
   Player *player = new Player();
   player->Kill(); // death by shnoo shnoo
   
   EXPECT_EQ(player->IsAlive(), false);
   EXPECT_EQ(player->GetHealth(), 0);
}

TEST(Player, RestoreToMax) {
   Player *player = new Player();
   player->Kill() ;
   
   EXPECT_EQ(player->GetHealth(), 0);
   
   player->RestoreToMax();
   EXPECT_EQ(player->GetHealth(), 100);
}

TEST(Player, Damage) {
   Player *player = new Player();
   player->SetMaxHealth(30);
   
   player->Damage(10);
   EXPECT_EQ(player->GetHealth(), 20);
   
   player->Damage(-10);
   EXPECT_EQ(player->GetHealth(), 30);
   
   player->Damage(-10);
   EXPECT_EQ(player->GetHealth(), 30);
   
   player->Damage(40);
   EXPECT_EQ(player->GetHealth(), 0);
   EXPECT_EQ(player->IsAlive(), false);
}

TEST(Player, Heal) {
   Player *player = new Player();
   player->SetMaxHealth(30);
   
   player->Heal(-10);
   EXPECT_EQ(player->GetHealth(), 20);
   
   player->Heal(5);
   EXPECT_EQ(player->GetHealth(), 25);
   
   player->Heal(100);
   EXPECT_EQ(player->GetHealth(), 30);
   
   player->Heal(-100);
   EXPECT_EQ(player->GetHealth(), 0);
   EXPECT_EQ(player->IsAlive(), false);
}
